﻿using DayuCode.Designer.Entity;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DayuCode.Designer.Forms
{
    public partial class FormColumns : UIForm
    {
        IList<HDataColumn> columns;
        public FormColumns()
        {
            InitializeComponent();
            dgvColums.AutoGenerateColumns = false;
        }

        public void SetColumns(IList<HDataColumn> columns)
        {
            this.columns = columns;
            dgvColums.DataSource = columns;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Close();
            DialogResult = DialogResult.OK;
        }

        private void btnSelectAll_Click(object sender, EventArgs e)
        {
            resetSelected(true);
        }

        private void btnUnSelectAll_Click(object sender, EventArgs e)
        {
            resetSelected(false);
        }

        private void resetSelected(bool selected)
        {
            
            if (columns == null) return;
            columns.ForEach(column => column.Selected = selected);
            dgvColums.Invalidate();
        }
    }
}
